<?php
namespace app\console\model;


use think\facade\Request;
use think\Loader;
use think\facade\Session;

class Login extends Base
{
    protected static function init()
    {


    }

    public function login()
    {
        $param = Request::param();
        $conditon = [
            'admin_name' => $param['admin_name'],
            'admin_password' => $param['admin_password'],
        ];
        $find_admin_name = Admin::get(['admin_name' => $param['admin_name']]);
        if (empty($find_admin_name)) {
            return '用户名不存在';
           // (new Admin())->error = '用户名不存在';
        }
        $find_name_password = Admin::get($conditon);
        if (empty($find_name_password)) {
            return '密码不正确';
        }
        $conditon[] = ['status' => 1];
        if (empty($find_name_password_status)) {
            return '该管理员被停用';
        }
        return true;


    }

    public static function chkPri(){
        $admin_id = Session::get('admin_id');
        $module = Request::module();
        $controller = Request::controller(true);
        $action = Request::action();
        $url = $module.'/'.$controller.'/'.$action;
        $pri = AdminRole::alias('admin_role')
            ->join('role_pri','admin_role.role_id = role_pri.role_id','LEFT')
            ->join('privilege','role_pri.pri_id = privilege.id','LEFT')
            ->where('admin_role.admin_id','eq',$admin_id)
            ->where('url','eq',$url)
            ->where('privilege.status',1)
            ->field('url')
            ->count();
        return ($pri > 0);
    }


}